import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
// const originalPush = VueRouter.prototype.push = function push(location) {
//     return originalPush.call(this, location).catch(err => err)
// }


// const originalPush = VueRouter.prototype.push = function push(location, onResolve, onReject) {
//     // 成功或者失败的回调
//     if (onResolve || onReject) {
//         return originalPush.call(this, location, onResolve, onReject)
//     }
//     // 没有指定成功或者失败的回调，要用catch处理
//     return originalPush.call(this, location).catch((err) => {
//         // 如果是重复导航产生的错误，不再向外传递错误
//         if (VueRouter.isNavigationFailure(err)) {
//             return err
//         }
//         // 如果不是重复导航的错误，将错误向下传递
//         return Promise.reject(err)
//     })
// }



const routes = [
    {
        path: '/',
        name: 'login',
        component: () => import('../views/login.vue')
    },
    {
        path: '/regist',
        name: 'regist',
        component: () => import('../views/regist.vue')
    },
    {
        path: '/home',
        name: 'home',
        component: () => import('../views/home.vue'),
        redirect: '/manageNews',

        children: [
            // 新闻资讯
            {
                path: '/manageNews',
                name: 'manageNews',
                component: () => import('../views/index/manageNews.vue')
            },
            {
                path: '/addNews',
                name: 'addNews',
                component: () => import('../views/index/addNews.vue')
            },
            // 加入我们
            {
                path: '/addJob',
                name: 'addJob',
                component: () => import('../views/addWe/addJob.vue')
            },
            {
                path: '/manageDetail',
                name: 'manageDetail',
                component: () => import('../views/addWe/manageDetail.vue')
            },
            // 官网
            {
                path: '/setting',
                name: 'setting',
                component: () => import('../views/website/setting.vue')
            },
            // 历程管理
            {
                path: '/addHistory',
                name: 'addHistory',
                component: () => import('../views/history/addHistory.vue')
            },
            {
                path: '/history',
                name: 'history',
                component: () => import('../views/history/history.vue')
            },
            // 产品方案
            {
                path: '/addProduct',
                name: 'addProduct',
                component: () => import('../views/product/addProduct.vue')
            },
            {
                path: '/productMessage',
                name: 'productMessage',
                component: () => import('../views/product/productMessage.vue')
            },
            // 合作伙伴
            {
                path: '/addBuddy',
                name: 'addBuddy',
                component: () => import('../views/buddy/addBuddy.vue')
            },
            {
                path: '/buddy',
                name: 'buddy',
                component: () => import('../views/buddy/buddy.vue')
            },
            // 关于我们
            {
                path: '/about',
                name: 'about',
                component: () => import('../views/about/about.vue')
            },
            // 轮播图
            {
                path: '/swipper',
                name: 'swipper',
                component: () => import('../views/swipper/swipper.vue')
            },
            {
                path: '/swipperSetting',
                name: 'swipperSetting',
                component: () => import('../views/swipper/swipperSetting.vue')
            },
        ]
    }

]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})


export default router
